﻿Imports Microsoft.Office.Interop.Outlook

Namespace UI
    Public MustInherit Class pmBaseFolderTreeForm
        Protected _app As Outlook.Application

        Protected _pmFoldertree As pmFoldertree
        Private ReadOnly _searchPattern As String

        Public Event ActionButtonClicked()

        Friend Sub New(ByVal App As Outlook.Application)
            If IsNothing(App) Then
                Throw New ArgumentNullException("App")
            End If
            _app = App

            ' This call is required by the Windows Form Designer.
            InitializeComponent()
        End Sub

        Private Sub pmBaseFolderTreeForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            initializeTreeview()
        End Sub

        Protected Sub initializeTreeview()
            Dim i As Integer = 0
            While i <> Panel1.Controls.Count
                Panel1.Controls.RemoveAt(i)
            End While

            _pmFoldertree = New pmFoldertree(_app)
            Panel1.Controls.Add(_pmFoldertree)
        End Sub

        Public Sub SelectRelevantFolder(ByVal searchPattern As String)
            _pmFoldertree.SearchPattern = searchPattern
            _pmFoldertree.SelectRelevantFolder()
        End Sub
        Public Sub SelectFolder(ByVal folder As MAPIFolder)
            _pmFoldertree.SelectFolderInTree(folder)
        End Sub

        Private Sub CloseWindow()
            Me.Close()
        End Sub


#Region "Form Events"
        Friend Sub btnDoAction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoAction.Click
            RaiseEvent ActionButtonClicked()
        End Sub
        Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            CloseWindow()
        End Sub
        Private Sub txtSearchBox_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSearchBox.KeyUp
            SelectRelevantFolderBySearchBox()
        End Sub
        Private Sub btnClearSearchBox_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClearSearchBox.Click
            txtSearchBox.Clear()
            SelectRelevantFolderBySearchBox()
        End Sub
#End Region

        Private Sub SelectRelevantFolderBySearchBox()
            _pmFoldertree.SearchPattern = txtSearchBox.Text
            _pmFoldertree.SelectRelevantFolder()
        End Sub

        Public MustOverride Sub pmForm_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

    End Class



End Namespace